package com.example.test9;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.Nullable;

public class MyDatabaseHelper extends SQLiteOpenHelper {

    public static final String CREATE_CONTACTS = "create table Contacts ("
            + "id integer primary key autoincrement, "
            + "name text,"
            + "number integer,"
            + "gender text)";

    private Context mContext;
    public MyDatabaseHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mContext = context;
    }


    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(CREATE_CONTACTS);
        Toast.makeText(mContext,"创建成功",Toast.LENGTH_SHORT).show();
        Log.d("MainActivity3","创建成功");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {
        db.execSQL("drop table if exists Contacts");
        onCreate(db);
    }
}
